package com.yun.zf.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.zf.common.app.domain.ZfCommunity;
import com.yun.zf.common.app.dto.community.CommunityInfo;
import com.yun.zf.common.app.dto.community.CommunityTotal;
import com.yun.zf.common.app.dto.detail.CommunityNearByDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 社区表 Mapper 接口
 * </p>
 *
 * @author cj
 * @since 2021-01-29
 */
@Mapper
public interface ZfCommunityMapper extends BaseMapper<ZfCommunity> {

    @Select("<script>" +
            " SELECT  zc.id, zc.province_code ,zc.city_code,zc.region_name,zc.street_name,zc.community_name,zc.cty_build_year,zc.development,zc.property_company,zc.brand_reason ,cp.url from zf_community zc \n" +
            "             LEFT JOIN (SELECT community_id ,url from zf_community_picture p WHERE  p.type=0) cp on zc.id =cp.community_id   WHERE  zc.is_brand_c='Y' and zc.city_code=#{cityCode}  " +
            "</script>")
    public List<CommunityNearByDto> getBrandCommunity(Long cityCode, Page<CommunityNearByDto> page);

    @Select("<script>" +
            " SELECT  s.total,s.type from  zf_community_statistical s WHERE s.community_id=#{communityId} " +
            "</script>")
    public List<CommunityTotal> ctotal(Long communityId);

    @Select("<script>" +
            " SELECT c.location from zf_community c  WHERE   c.id=#{communityId} " +
            "</script>")
    public  CommunityNearByDto getCommunityInfo(Long communityId);

    @Select("<script>" +
            " SELECT  zc.id, zc.province_code ,zc.city_code,zc.region_name,zc.street_name,zc.community_name,zc.cty_build_year,zc.development,zc.property_company,zc.brand_reason ,cp.url from zf_community zc \n" +
            "   LEFT JOIN (SELECT community_id ,url from zf_community_picture p WHERE  p.type=0) cp on zc.id =cp.community_id " +
            "WHERE   zc.id IN " +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')' > " +
            "  #{item} " +
            "  </foreach> " +
            "</script>")
    List<CommunityNearByDto> getBasicCommunity(@Param("ids") List<Long> ids);


    @Select("<script>" +
            "SELECT zc.province_code,zc.city_code,zc.location, zc.community_name,zc.cty_build_year,zc.development,zc.total_building,zc.total_house,zc.property_company,zc.property_tel,zc.property_costs,zc.heating\n" +
            ",zc.parking_ground,zc.parking_under,zc.parking_under_fee,zc.parking_ground_fee ,zs.average_price ,zs.rent_total,zs.sale_total from zf_community zc \n" +
            "            LEFT JOIN zf_community_statistical zs on zc.id=zs.community_id \n" +
            "            WHERE   zc.id = #{id}" +
            "</script>")
    CommunityInfo getDetailInfo(Long id);
}
